﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using csharp_webapi_415.Data;
using csharp_webapi_415.Data.Models;

namespace csharp_webapi_415.Controllers
{
    public class FlicksActorsTempController : ApiController
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        // GET: api/FlicksActorsTemp
        public IQueryable<FlicksActors> GetFlickActor()
        {
            return db.FlickActor;
        }

        // GET: api/FlicksActorsTemp/5
        [ResponseType(typeof(FlicksActors))]
        public IHttpActionResult GetFlicksActors(int id)
        {
            FlicksActors flicksActors = db.FlickActor.Find(id);
            if (flicksActors == null)
            {
                return NotFound();
            }

            return Ok(flicksActors);
        }

        // PUT: api/FlicksActorsTemp/5
        [ResponseType(typeof(void))]
        public IHttpActionResult PutFlicksActors(int id, FlicksActors flicksActors)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != flicksActors.FlicksActorsId)
            {
                return BadRequest();
            }

            db.Entry(flicksActors).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlicksActorsExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }

        // POST: api/FlicksActorsTemp
        [ResponseType(typeof(FlicksActors))]
        public IHttpActionResult PostFlicksActors(FlicksActors flicksActors)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.FlickActor.Add(flicksActors);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = flicksActors.FlicksActorsId }, flicksActors);
        }

        // DELETE: api/FlicksActorsTemp/5
        [ResponseType(typeof(FlicksActors))]
        public IHttpActionResult DeleteFlicksActors(int id)
        {
            FlicksActors flicksActors = db.FlickActor.Find(id);
            if (flicksActors == null)
            {
                return NotFound();
            }

            db.FlickActor.Remove(flicksActors);
            db.SaveChanges();

            return Ok(flicksActors);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }

        private bool FlicksActorsExists(int id)
        {
            return db.FlickActor.Count(e => e.FlicksActorsId == id) > 0;
        }
    }
}